package com.blog.quartzTest;

import org.quartz.*;
import org.quartz.impl.StdSchedulerFactory;

import java.util.concurrent.TimeUnit;

import static org.quartz.JobBuilder.newJob;
import static org.quartz.SimpleScheduleBuilder.simpleSchedule;
import static org.quartz.TriggerBuilder.newTrigger;

/**
 * @author cgx
 * @Date 2021/11/23 16:45
 */
public class _03_third {
    public static void main(String[] args) {
        try {
            Scheduler scheduler = new StdSchedulerFactory().getScheduler();
            scheduler.start();

            JobDetail job = newJob(helloQuartz.class)
                    .withIdentity("job1","group1")
                    .build();

            Trigger trigger = newTrigger()
                    .withIdentity("trigger1","group1")
                    .startNow()
                    .withSchedule(
                            /**
                             * 1. 一共七位，分别代表： 秒、分、时、天、月、星期、年
                             * 2. * * * * * ? *分别代表每秒、没分、每时、每天、每星期、每年都执行
                             *
                             * 含义：*代表每一个，？代表不知道
                             */
                            CronScheduleBuilder.cronSchedule("0/5 * * * * ? *")
                    )
                    .build();

            scheduler.scheduleJob(job, trigger);

            TimeUnit.SECONDS.sleep(3000);
            scheduler.shutdown();
        }catch (Exception e){

        }
    }
}
